package com.sxx.beautifulcity.popmenu;

import android.content.Intent;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.Toast;

import com.sxx.beautifulcity.R;
import com.sxx.beautifulcity.activity.JudgeActivity;
import com.sxx.beautifulcity.activity.JudgeSoftActivity;
import com.sxx.beautifulcity.activity.StoreActivity;
import com.sxx.beautifulcity.application.ProjectApplication;
import com.sxx.beautifulcity.database.AgritourismHelper;
import com.sxx.beautifulcity.database.DetailStoreHelpter;
import com.sxx.beautifulcity.entity.greendao.Detail;
import com.sxx.beautifulcity.utils.NetWorkUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 15/11/4.
 */
public class CommonPopMenu {

    private static DetailStoreHelpter helpter;

    public CommonPopMenu() {

    }

    public static PopupMenu setHelpShopPopMenu(final View anchor, final String url) {
        PopupMenu pm = new PopupMenu(ProjectApplication.getContext(), anchor);
        // 加载菜单文件
        pm.inflate(R.menu.menu_main);

        // 设置菜单项的点击事件
        pm.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // TODO Auto-generated method stub
                if (item.getItemId() == R.id.giveupItem) {
                    helpter = new DetailStoreHelpter();
                    List<Detail> list = new ArrayList<Detail>();
                    Detail detail = new Detail();
                    detail.setPath(url);
                    list.add(detail);
                    Log.i("hjdjgvhfd", list + "");
                    helpter.saveDetailList(list);
                    Toast.makeText(ProjectApplication.getContext(), "已收藏", Toast.LENGTH_SHORT).show();
                } else if (item.getItemId() == R.id.mergeItem) {
                    boolean network = NetWorkUtils.checkNet(ProjectApplication.getContext());
                    if (network == true) {
                        Intent intent = new Intent();
                        intent.setClass(ProjectApplication.getContext(), JudgeActivity.class);
                        anchor.getContext().startActivity(intent);
                    } else {
                        Toast.makeText(ProjectApplication.getContext(), "请检查网络", Toast.LENGTH_SHORT).show();
                    }

                } else if (item.getItemId() == R.id.otherItem) {

                }
                return false;
            }
        });
        pm.show();// 显示菜单
        return pm;
    }


}
